﻿namespace Sidvall.CodeGenerator
{
	public class NamespaceMappingCollection : System.Collections.ObjectModel.KeyedCollection<string, NamespaceMapping>
	{
		#region Public Members

		public void Add(string @namespace, string newNamespace)
		{
			NamespaceMapping item;

			item = new NamespaceMapping()
			{
				Namespace = @namespace,
				NewNamespace = newNamespace,
				Ignore = false
			};
			Add(item);
		}
		public void Ignore(string @namespace)
		{
			NamespaceMapping item;

			item = new NamespaceMapping()
			{
				Namespace = @namespace,
				Ignore = true
			};
			Add(item);
		}
		public NamespaceMapping GetItem(string @namespace)
		{
			if (string.IsNullOrWhiteSpace(@namespace))
				return null;
			@namespace = @namespace.ToUpperInvariant();
			if (Contains(@namespace))
				return this[@namespace];
			else
				return null;
		}
		protected override string GetKeyForItem(NamespaceMapping item)
		{
			if (item == null)
				throw new System.ArgumentNullException("item");
			return item.Namespace.ToUpperInvariant();
		}
		#endregion
		#region Constructors

		public NamespaceMappingCollection()
			: base(System.StringComparer.OrdinalIgnoreCase)
		{
		}

		#endregion
	}
}
